package com.sl.core.engine.factory;

import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil;
import com.sl.core.engine.meta.valuemeta.ValueMetaArray;
import com.sl.core.engine.meta.valuemeta.ValueMetaObject;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.value.*;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.Map;

public class ProcessConfigFactory {

    public static IValueMeta guessValueMetaInterface(Object object) {
        if(ObjectUtil.isNull(object)){
            return null;
        }
        if (object instanceof Number) {
            // this is numeric object
            if (object instanceof BigDecimal) {
                return new ValueMetaBigNumber();
            } else if (object instanceof Double) {
                return new ValueMetaNumber();
            } else if (object instanceof Long) {
                return new ValueMetaInteger();
            } else if (object instanceof Integer) {
                return new ValueMetaInteger();
            }
        } else if (object instanceof String) {
            return new ValueMetaString();
        } else if (object instanceof Date) {
            return new ValueMetaDate();
        } else if (object instanceof Boolean) {
            return new ValueMetaBoolean();
        } else if (object instanceof byte[]) {
            return new ValueMetaBinary();
        } else if (object instanceof Map) {
            return new ValueMetaObject();
        } else if (object instanceof Collection) {
            return new ValueMetaArray();
        } else if (!ClassUtil.isSimpleValueType(object.getClass())) {
            return new ValueMetaObject();
        }
        // ask someone else
        return null;
    }
}
